﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System.Text;
using OfficeOpenXml;

namespace Core
{
    public class Configuration
    {
        private static Team team = new Team();

        public static string TfsUri
        {
            get
            {
                return ConfigurationManager.AppSettings["TfsUri"];
            }
        }

        public static string Project
        {
            get
            {
                return ConfigurationManager.AppSettings["Project"];
            }
        }

        public static string Query
        {
            get
            {
                return ConfigurationManager.AppSettings["Query"];
            }
        }

        public static Team Team
        {
            get
            {
                return team;
            }
        }

        public static string ReportFilePath
        {
            get
            {
                return ConfigurationManager.AppSettings["ReportFilePath"];
            }
        }

        public static string Exchange
        {
            get
            {
                return ConfigurationManager.AppSettings["Exchange"];
            }
        }

        private static string reportDateValue;

        public static string ReportDateValue
        {
            get 
            { 
                if (reportDateValue == null) 
                    reportDateValue = ConfigurationManager.AppSettings["ReportDate"];
                return reportDateValue;
            }
            set 
            {
                reportDateValue = value;
            }
        }

        public static DateTime ReportDate
        {
            get
            {
                return ParseDate(ReportDateValue);
            }
        }

        private static string reportFinalDateValue;

        public static string ReportFinalDateValue
        {
            get
            {
                if (reportFinalDateValue == null)
                    reportFinalDateValue = ConfigurationManager.AppSettings["ReportFinalDate"];
                return reportFinalDateValue;
            }
            set
            {
                reportFinalDateValue = value;
            }
        }

        public static DateTime ReportFinalDate
        {
            get
            {
                var value = ParseDate(reportFinalDateValue);
                if (ReportDate == value)
                    value = value.AddDays(1);
                return value;
            }
        }

        public static bool SendEmails
        {
            get
            {
                return bool.Parse(ConfigurationManager.AppSettings["SendEmails"]);
            }
        }

        private static DateTime ParseDate(string value)
        {
            if (String.IsNullOrEmpty(value) || value == "today")
                return DateTime.Today;
            if (value == "yesterday")
                return DateTime.Today.AddDays(-1);
            if (value == "tomorrow")
                return DateTime.Today.AddDays(1);
            return DateTime.Parse(value);
        }
    }
}
